package com.boarsoft.boar.soagov.face.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.entity.FaceInfo;
import com.boarsoft.boar.soagov.face.FaceBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.action.PageAction;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.common.util.JsonUtil;

@SuppressWarnings("serial")
@Component
@Scope("prototype")
@ParentPackage("default-package")
@Namespace(value = "/face")
public class FaceAction extends PageAction {
	@Autowired
	private FaceBiz faceBiz;
	//
	private String id;
	private String key;// 查询用
	private String code;
	private String name;
	private String face;
	private String entry;
	private String memo;
	private String ver;

	/**
	 * 查询所有接口
	 */
	@Action("list")
	// @Authorized(code = "face.list")
	public void list() {
		PagedResult<FaceInfo> fiPr = faceBiz.list(key, orderBy, pageNo, pageSize);
		writeReply(true, JsonUtil.from(fiPr));
	}

	@Action("save")
	public void save() {
		FaceInfo c = null;
		if (Util.strIsEmpty(id)) {
			c = new FaceInfo();
		} else {
			c = faceBiz.get(id);
		}
		c.setCode(code);
		c.setName(name);
		c.setFace(face);
		c.setEntry(entry);
		c.setVer(ver);
		c.setMemo(memo);
		faceBiz.save(c);
		writeReply();
	}

	@Action("delete")
	@Authorized(code = "face.delete")
	public void delete() {
		if (!this.isValid("id")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		}
		faceBiz.delete(id);
		writeReply();
	}

	@Action("get")
	@Authorized(code = "face.get")
	public void get() {
		if (!this.isValid("id")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		}
		FaceInfo a = faceBiz.get(id);
		writeReply(true, JsonUtil.from(a));
	}

	// ---------------

	public String getCode() {
		return code;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public FaceBiz getFaceBiz() {
		return faceBiz;
	}

	public void setFaceBiz(FaceBiz faceBiz) {
		this.faceBiz = faceBiz;
	}

	public String getVer() {
		return ver;
	}

	public void setVer(String ver) {
		this.ver = ver;
	}

	public String getFace() {
		return face;
	}

	public void setFace(String face) {
		this.face = face;
	}

	public String getEntry() {
		return entry;
	}

	public void setEntry(String entry) {
		this.entry = entry;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}
}